import router from "./router"
import { getLocalToken } from "./utils/auth"
import NProgress from 'nprogress';
import 'nprogress/nprogress.css'

//白名单
const WhiteList=['/login','/404']
//全局路由守卫
router.beforeEach((to,from,next)=>{
    //开启精度条
    NProgress.start()
    const token=getLocalToken()
    if(token){
        //使用next()放行
        //判断是不是去登录页,如果是的话,就直接跳转到首页
        if(to.path==='/login'){
            next('/')
        }else {
            next ()
        }
    }else{
        if(WhiteList.includes(to.path)){
            next()
        }else {
            next('/login')
        }
    }
})

//路由后置守卫 (一般用来修改标题)
router.afterEach((to,from)=>{
    // console.log(to)
    document.title=to.meta.title||'IKUN见面会'
    //关闭精度条
    NProgress.done()
})